% This program is written for use in Matlab.  It generates figures 1 and 3;

data = dlmread('newfigure1_data.txt','\t',1,0);

grid_limit_x = data(1:50,1);
grid_limit_y = data(1:50,2);
ci95_high_limit = data(1:50,3);
ci95_low_limit = data(1:50,4);
grid_pctblack_x = data(1:50,5);
grid_pctblack_y = data(1:50,6);
ci95_high_pctblack = data(1:50,7);
ci95_low_pctblack = data(1:50,8);
grid_score1_x = data(1:50,9);
grid_score1_y = data(1:50,10);
ci95_high_score1 = data(1:50,11);
ci95_low_score1 = data(1:50,12);
grid_score2_x = data(1:50,13);
grid_score2_y = data(1:50,14);
ci95_high_score2 = data(1:50,15);
ci95_low_score2 = data(1:50,16);

clear data

figure(1);
clf;
set(gcf,'PaperUnits','inches','PaperPosition',[0 0 6 3]);

% This block of code (down to the "print" statement) will generate Figure 1;
subplot(1,2,1);
fill([grid_limit_x' fliplr(grid_limit_x')],[ci95_high_limit' fliplr(ci95_low_limit')],[0.85 0.85 0.85],'LineStyle','none');
title(['A) Distortion in Aggregate Balances';'by Aggregate Credit Limits         ']); %'Credit Limit with 95 Percent Confidence Interval']);
xlabel('Credit Limits (LIMIT, in $000s)');
ylabel(['UTIL$ - BAL (in $000s)']);
xlim([-10,240]);
ylim([-60,5]);
legend('95% CI','Location','SouthWest');
legend boxoff;
%axis([0 1 0 12]);
hold on;
plot(grid_limit_x,grid_limit_y,'k',grid_limit_x,zeros(50,1),'k--');
hold off;
set(gca,'position',[0.1 0.14 0.35 0.7]);

subplot(1,2,2);
fill([grid_pctblack_x' fliplr(grid_pctblack_x')],[ci95_high_pctblack' fliplr(ci95_low_pctblack')],[0.85 0.85 0.85],'LineStyle','none');
title(['B) Distortion in Aggregate Balances';'by Neighborhood Racial Composition ']); %;'Racial Composition with 95 Percent Confidence Interval']);
xlabel('Racial Composition (%BLACK)');
ylabel(['UTIL$ - BAL (in $000s)']);
xlim([-0.05,1.05]);
ylim([-3,0.4]);
legend('95% CI','Location','SouthEast');
legend boxoff
%axis([0 1 0 12]);
hold on;
plot(grid_pctblack_x,grid_pctblack_y,'k',grid_pctblack_x,zeros(50,1),'k--');
hold off;
set(gca,'position',[0.6 0.14 .35 .7]);
print -dpng NewFigure1.png -r100

% This block of code generates figure 3;
figure(2);
clf;
set(gcf,'PaperUnits','inches','PaperPosition',[0 0 6 6]);
plot(grid_score1_x,grid_score1_y,'k');
hold on;
plot(grid_score2_x,grid_score2_y,'k--');
fill([grid_score1_x' fliplr(grid_score1_x')],[ci95_high_score1' fliplr(ci95_low_score1')],[0.85 0.85 0.85],'LineStyle','none');
fill([grid_score2_x' fliplr(grid_score2_x')],[ci95_high_score2' fliplr(ci95_low_score2')],[0.85 0.85 0.85],'LineStyle','none');
plot(grid_score1_x,grid_score1_y,'k');
plot(grid_score2_x,grid_score2_y,'k--');
hold off;
legend(['Estimation Sample                             ';'Estimation Sample with Exclusion Effect Sample';'95% Confidence Interval                       '],'Location','SouthWest')
legend boxoff;
xlabel('Neighborhood Racial Composition (%BLACK)');
ylabel('Mean Credit Score');
xlim([-0.05,1.05]);
ylim([450,750]);
%axis([0 1 0 12]);
print -dpng NewFigure3.png -r100
